#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Creaet Time    : 2021/10/18 22:19
# @File           : schemas.py
# @IDE            : PyCharm
# @desc           : pydantic 模型，用于数据库序列化操作

# pydantic 验证数据：https://blog.csdn.net/qq_44291044/article/details/104693526


import re
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, validator
from core.validator import vali_telephone, ValiDatetime


class SadminAuthUser(BaseModel):
    name: str
    telephone: str
    nickname: Optional[str] = None
    avatar: Optional[str] = None
    wechat: Optional[str] = None
    qq: Optional[str] = None
    is_active: bool = True
    gender: Optional[str] = "0"

    # validators
    _normalize_telephone = validator('telephone', allow_reuse=True)(vali_telephone)

    class Config:
        # 示例参数值，会默认显示在接口文档中，example为固定写法
        schema_extra = {
            "example": {
                "name": "姓名",
                "nickname": "昵称",
                "telephone": "13459782158",
                "wechat": "weixinhao",
                "qq": "123456",
                "gender": "123456",
                "is_active": True,
            }
        }


class SadminAuthUserOut(SadminAuthUser):
    id: int
    joined_time: ValiDatetime
    update_time: ValiDatetime

    class Config:
        orm_mode = True


class SadminAuthUserUpdate(BaseModel):
    name: str
    nickname: Optional[str] = None
    avatar: Optional[str] = None
    wechat: Optional[str] = None
    qq: Optional[str] = None
    gender: Optional[str] = "0"

    class Config:
        # 示例参数值，会默认显示在接口文档中，example为固定写法
        schema_extra = {
            "example": {
                "name": "姓名",
                "nickname": "昵称",
                "wechat": "weixinhao",
                "qq": "123456",
                "gender": "123456",
                "is_active": True,
            }
        }
